<div class="content-wrapper" [@routerTransition]>
    <sub-header idName="Tenants" [title]="'Tenants' | localize" [description]="'TenantsHeaderInfo' | localize">
        <div role="actions">
            <button *ngIf="'Pages.Tenants.Create' | permission" class="btn btn-primary blue  mr-1" (click)="createTenant()">
                <i class="fa fa-plus"></i>{{"CreateNewTenant" | localize}}
            </button>
            <button *ngIf="'Pages.Tenants.ConfigFileEdit' | permission" class="btn btn-primary blue  mr-1" (click)="config()">
                <i class="fa fa-cog"></i>{{"ConfigFile" | localize}}
            </button>
            <button *ngIf="'Pages.Tenants.SuperUser' | permission" class="btn btn-primary blue" (click)="removeSuperUsers()">
                <i class="fa fa-times"></i>{{"移除超级管理员" | localize}}
            </button>
        </div>
    </sub-header>
    <section class="content d-flex flex-column flex-column-fluid">
        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">
                    <div class="form">
                        <form  autocomplete="new-password">
                            <div class="form-body">
                                <div class="row mb-4">
                                    <div class="col-xl-12">
                                        <div class="input-group">
                                            <input id="TenantNameOrTenancyCode" [(ngModel)]="filters.filterText"
                                                name="filterText" class="form-control"
                                                placeholder="{{'SearchWithThreeDot' | localize}}" type="text">
                                            <div class="input-group-append">
                                                <button class="btn btn-default" (click)="getTenants()"><i
                                                        class="icon-magnifier"
                                                        [attr.aria-label]="l('Search')"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="row align-items-center">
                        <!--<Primeng-TurboTable-Start>-->
                        <div class="col primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <p-table #dataTable sortMode="multiple" (onLazyLoad)="getTenants($event)"
                                [value]="primengTableHelper.records"
                                rows="{{primengTableHelper.defaultRecordsCountPerPage}}" [paginator]="false"
                                [lazy]="true" [responsive]="primengTableHelper.isResponsive">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th style="width:130px">{{'Actions' | localize}}</th>
                                        <th pSortableColumn="tenancyName">
                                            {{'TenancyCodeName' | localize}}
                                            <p-sortIcon field="tenancyName"></p-sortIcon>
                                        </th>
                                        <th pSortableColumn="name">
                                            {{'TenantName' | localize}}
                                            <p-sortIcon field="name"></p-sortIcon>
                                        </th>
                                        <th>{{'Edition' | localize}}</th>
                                        <th pSortableColumn="isActive">
                                            {{'Active' | localize}}
                                            <p-sortIcon field="isActive"></p-sortIcon>
                                        </th>
                                        <th pSortableColumn="creationTime">
                                            {{'CreationTime' | localize}}
                                            <p-sortIcon field="creationTime"></p-sortIcon>
                                        </th>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record="$implicit">
                                    <tr>
                                        <td style="width: 130px">
                                            <div class="btn-group" dropdown placement="bottom left">
                                                <button id="dropdownButton" type="button"
                                                    class="btn btn-primary btn-xs2 blue dropdown-toggle" dropdownToggle
                                                    aria-controls="dropdownMenu">
                                                    <i class="fa fa-cog"></i><span class="caret"></span>
                                                    {{"Actions" | localize}}
                                                </button>
                                                <ul id="dropdownMenu" class="dropdown-menu" role="menu" *dropdownMenu
                                                    aria-labelledby="dropdownButton">
                                                    <li *ngIf="'Pages.Tenants.Impersonation' | permission"
                                                        [class.disabled]="!record.isActive" role="menuitem">
                                                        <a href="javascript:;" class="dropdown-item"
                                                            [class.disabled]="!record.isActive"
                                                            (click)="record.isActive && showUserImpersonateLookUpModal(record)">{{'LoginAsThisTenant'
                                                            | localize}}</a>
                                                    </li>
                                                    <li *ngIf="'Pages.Tenants.Edit' | permission" role="menuitem">
                                                        <a href="javascript:;" class="dropdown-item"
                                                            (click)="editTenantModal.show(record.id)">{{'Edit' |
                                                            localize}}</a>
                                                    </li>
                                                    <li *ngIf="'Pages.Tenants.ChangeFeatures' | permission"
                                                        role="menuitem">
                                                        <a href="javascript:;" class="dropdown-item"
                                                            (click)="tenantFeaturesModal.show(record.id, record.name)">{{'Features'
                                                            | localize}}</a>
                                                    </li>
                                                    <li *ngIf="'Pages.Tenants.Delete' | permission" role="menuitem">
                                                        <a href="javascript:;" class="dropdown-item"
                                                            (click)="deleteTenant(record)">{{'Delete' | localize}}</a>
                                                    </li>
                                                    <li role="menuitem">
                                                        <a href="javascript:;" class="dropdown-item"
                                                            (click)="unlockUser(record)">{{'Unlock' | localize}}</a>
                                                    </li>
                                                    <li *ngIf="'Pages.Tenants.SuperUser' | permission" role="menuitem">
                                                        <a href="javascript:;" class="dropdown-item"
                                                           (click)="addSuperUser(record)">{{'添加超级管理' | localize}}</a>
                                                    </li>
                                                    <li *ngIf="entityHistoryEnabled" role="menuitem">
                                                        <a href="javascript:;" class="dropdown-item"
                                                            (click)="showHistory(record)">{{'History' | localize}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td>
                                            <span class="p-column-title">{{'TenancyCodeName' | localize}}</span>
                                            <i *ngIf="record.connectionString" class="fa fa-database"
                                                title="{{'HasOwnDatabase' | localize}}"></i>
                                            {{record.tenancyName}}
                                        </td>
                                        <td>
                                            <span class="p-column-title">{{'Name' | localize}}</span>
                                            {{record.name}}
                                        </td>
                                        <td>
                                            <span class="p-column-title">{{'Edition' | localize}}</span>
                                            {{record.editionDisplayName}}
                                        </td>
                                        <td>
                                            <span class="p-column-title">{{'Active' | localize}}</span>
                                            <span *ngIf="record.isActive"
                                                class="label label-success label-inline">{{'Yes' | localize}}</span>
                                            <span *ngIf="!record.isActive" class="label label-dark label-inline">{{'No'
                                                | localize}}</span>
                                        </td>
                                        <td>
                                            <span class="p-column-title">{{'CreationTime' | localize}}</span>
                                            {{record.creationTime | luxonFormat:'F'}}
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
                                {{'NoData' | localize}}
                            </div>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getTenants($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage"
                                    [showCurrentPageReport]="true"
                                    [currentPageReportTemplate]="'TotalRecordsCount' | localize:primengTableHelper.totalRecordsCount">
                                </p-paginator>
                            </div>
                        </div>
                        <!--<Primeng-TurboTable-End>-->
                    </div>
                </div>
            </div>
        </div>

        <createTenantModal #createTenantModal (modalSave)="getTenants()"></createTenantModal>
        <editTenantModal #editTenantModal (modalSave)="getTenants()"></editTenantModal>
        <tenantFeaturesModal #tenantFeaturesModal></tenantFeaturesModal>
        <commonLookupModal #impersonateUserLookupModal (itemSelected)="impersonateUser($event)"></commonLookupModal>
        <entityTypeHistoryModal #entityTypeHistoryModal></entityTypeHistoryModal>
        <json-editor-modal #jsonEditorModal (callback)="configSave($event)"></json-editor-modal>
    </section>
</div>
